/**
 * Project: eraclient
 * 
 * File Created at 2011-2-24
 * $Id$
 * 
 * Copyright 1999-2100 Alibaba.com Corporation Limited.
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of
 * Alibaba Company. ("Confidential Information").  You shall not
 * disclose such Confidential Information and shall use it only in
 * accordance with the terms of the license agreement you entered into
 * with Alibaba.com.
 */
package com.ymkyve.eraclient;

import java.awt.AWTException;
import java.awt.Image;
import java.awt.MenuItem;
import java.awt.PopupMenu;
import java.awt.SystemTray;
import java.awt.Toolkit;
import java.awt.TrayIcon;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JOptionPane;

/**
 * TODO Comment of Main
 * @author gaoliang
 *
 * @date 2011-2-24
 */
public class Main {
    public static void main(String args[]) {
        TrayIcon trayIcon = null;
        if (SystemTray.isSupported()) // 判断系统是否支持系统托盘
        {
            SystemTray tray = SystemTray.getSystemTray(); // 创建系统托盘
            Image image = Toolkit.getDefaultToolkit().getImage("D://56.gif");// 载入图片,这里要写你的图标路径哦
            ActionListener listener = new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    new Login();
                }
            };
            // 创建弹出菜单
            PopupMenu popup = new PopupMenu();
            MenuItem defaultItem = new MenuItem("主界面");
            defaultItem.addActionListener(listener);
            MenuItem exitItem = new MenuItem("退出程序");
            exitItem.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    if (JOptionPane.showConfirmDialog(null, "确定退出系统") == 0) {
                        System.exit(0);
                    }
                }
            });
            popup.add(defaultItem);
            popup.add(exitItem);
            trayIcon = new TrayIcon(image, "seara", popup);// 创建trayIcon
            trayIcon.addActionListener(listener);
            try {
                tray.add(trayIcon);
            } catch (AWTException e1) {
                e1.printStackTrace();
            }
        }
    }
}
